package com.sinopac.action.SupervisorReconfirm;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import com.sinopac.actionCore.ActionCore;
import com.sinopac.entity.SupervisorReconfirm.SupvEntity;
import com.sinopac.model.SupervisorReconfirm.SupervisorReconfirmModel;

@Namespace("/SupervisorReconfirm")
@ParentPackage("struts-default")
public class SupervisorReconfirmAction extends ActionCore{

	private static final long serialVersionUID = 1L;
	private SupvEntity supvList;
	private String errorMsg = "";
	
	@Action(value="index",results={@Result(name="input",location="/form/SupervisorReconfirm/SupervisorReconfirm.jsp")})
	public String index(){
		SupervisorReconfirmModel srm = new SupervisorReconfirmModel();
		supvList = srm.getSupvList();
		return INPUT;
	}
	
	@Action(value="confirmAuthorize",results={@Result(name="success",location="/form/SupervisorReconfirm/confirmAuthorize.jsp")})
	public String confirmAuthorize(){
		if(supvList != null){
			SupervisorReconfirmModel srm = new SupervisorReconfirmModel();
			supvList = srm.processSupvEntity(supvList);
		}
		return SUCCESS;
	}
	
	@Action(value="executeTransactions",results={@Result(name="success",type="chain",location="index")})
	public String executeTransactions(){
		
		if(supvList != null){
			SupervisorReconfirmModel srm = new SupervisorReconfirmModel();
			String msg = srm.updateDB(supvList, (String)session.get("userName"));
			if(StringUtils.isNotBlank(msg)){
				errorMsg = msg;
			}else{
				errorMsg = "";
			}
		}
		return SUCCESS;
	}
	
	public SupvEntity getSupvList() {
		return supvList;
	}

	public void setSupvList(SupvEntity supvList) {
		this.supvList = supvList;
	}

	public String getErrorMsg() {
		return errorMsg;
	}

	public void setErrorMsg(String errorMsg) {
		this.errorMsg = errorMsg;
	}
}
